<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习四：定义一个函数，传入n（n为正整数），计算1~n数字的和</title>
  </head>

  <body>

  </body>
  <script>
    /* 
  练习四：定义一个函数，传入n（n为正整数），计算1~n数字的和
  */
    function getNumberSum(num) {
      var total = 0;
      for (var i = 1; i <= num; i++) {
        total += i;
      }
      return total;
    }
    console.log(getNumberSum(10)); //55
  </script>

</html>